<template>
  <transition name="slide-fade">
    <div
      class="sdrawer-container"
      v-if="visible"
    >
      <div
        class="sdrawer-outer"
        :style="`width: ${size}`"
      >
        <div class="sdrawer-title">
          <span class="s1">{{title}}</span>
          <span
            class="el-icon-close s2"
            @click="cancel"
          ></span>
        </div>

        <div
          class="sdrawer-inner"
          v-if="visible"
        >
          <vue-scroll>
            <slot></slot>
          </vue-scroll>
        </div>

        <div class="sdrawer-footer">
          <div
            align="right"
            style="margin-top: 8px"
          >
            <el-button @click="cancel">取消</el-button>
            <el-button
              :type="submitType"
              :loading="submitLoading"
              @click="yes"
            >{{submitLabel}}</el-button>
          </div>
        </div>
      </div>
    </div>
  </transition>
</template>

<script>
export default {
  name: "",
  props: {
    title: {
      type: String,
      default: "标题",
    },
    visible: {
      type: Boolean,
      default: false,
    },
    width: {
      type: [Number, String],
      default: 300,
    },
    submitLoading: {
      type: Boolean,
      default: false,
    },
    submitLabel: {
      type: String,
      default: "确定",
    },
    submitType: {
      type: String,
      default: "primary",
    },
  },
  watch: {
    width: {
      handler(val) {
        if (isNaN(val)) {
          this.size = val;
        } else {
          this.size = val + "px";
        }
      },
      immediate: true,
    },
  },
  data() {
    return {
      size: "300px",
    };
  },
  methods: {
    cancel() {
      this.$emit("update:visible", false);
    },
    yes() {
      this.$emit("yes");
    },
  },
};
</script>

<style lang="less" scoped>
.sdrawer-container {
  position: fixed;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  z-index: 2000;
  background: rgba(0, 0, 0, 0.5);
  .sdrawer-outer {
    position: absolute;
    right: 0px;
    top: 0px;
    height: 100%;
    background: #fff;
    overflow: hidden;
    .sdrawer-title {
      display: flex;
      height: 50px;
      padding: 0px 13px;
      border-bottom: 1px solid #ccc;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 15px;
      .s1 {
        font-size: 15px;
        font-weight: 500;
      }
      .s2 {
        font-size: 18px;
        font-weight: 500;
        cursor: pointer;
      }
    }
    .sdrawer-inner {
      height: calc(100% - 103px);
      overflow-x: hidden;
      overflow-y: auto;
    }
    .sdrawer-footer {
      position: absolute;
      width: calc(100% - 26px);
      padding: 0px 13px;
      height: 50px;
      border-top: 1px solid #ccc;
      bottom: 0px;
      right: 0px;
      background: #fff;
    }
  }
}
.slide-fade-enter-active {
  transition: all 0.3s ease;
}
.slide-fade-leave-active {
  transition: all 0.8s cubic-bezier(1, 0.5, 0.8, 1);
}
.slide-fade-enter, .slide-fade-leave-to
/* .slide-fade-leave-active for below version 2.1.8 */ {
  transform: translateX(10px);
  opacity: 0;
}
</style>